

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;


public class HinhAnh {


    public static void ChuyenMau(PixelAnh pix) {
        Pixel[][] data = pix.getData();

        for (int dong = 0; dong < pix.getHeight(); dong++) {
            for (int cot = 0; cot < pix.getWidth(); cot++) {
                int tam = (data[dong][cot].red + data[dong][cot].blue + data[dong][cot].green) / 3;
                data[dong][cot].red = tam;
                data[dong][cot].blue = tam;
                data[dong][cot].red = tam;
            }
        }

        pix.setData(data);
    }

    public static void MoAnh(PixelAnh pix) {
        //pi.transform(weight);
        int[][] weight = {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}};

        Pixel[][] data = pix.getData();

        for (int dong = 0; dong < pix.getHeight(); dong++) {
            for (int cot = 0; cot < pix.getWidth(); cot++) {
                data[dong][cot].red = (data[dong][cot].red >= 10) ? (data[dong][cot].red - 10) : data[dong][cot].red;
                data[dong][cot].blue = (data[dong][cot].blue >= 10) ? (data[dong][cot].blue - 10) : data[dong][cot].blue;
                data[dong][cot].green = (data[dong][cot].green >= 10) ? (data[dong][cot].green - 10) : data[dong][cot].green;
            }
        }

        pix.setData(data);
    }

    public static void PhaiMau(PixelAnh pix) {
        Pixel[][] data = pix.getData();

        for (int dong = 0; dong < pix.getHeight(); dong++) {
            for (int cot = 0; cot < pix.getWidth(); cot++) {
                data[dong][cot].red = (data[dong][cot].red <= 245) ? (data[dong][cot].red + 10) : data[dong][cot].red;
                data[dong][cot].blue = (data[dong][cot].blue <= 245) ? (data[dong][cot].blue + 10) : data[dong][cot].blue;
                data[dong][cot].green = (data[dong][cot].green <= 245) ? (data[dong][cot].green + 10) : data[dong][cot].green;
            }
        }

        pix.setData(data);
    }

    public static void TrangDen(PixelAnh pix) {
        Pixel[][] data = pix.getData();

        for (int dong = 0; dong < pix.getHeight(); dong++) {
            for (int cot = 0; cot < pix.getWidth(); cot++) {
                data[dong][cot].red = 255 - data[dong][cot].red;
                data[dong][cot].blue = 255 - data[dong][cot].blue;
                data[dong][cot].green = 255 - data[dong][cot].green;
            }
        }

        pix.setData(data);
    }

    
     
      
        public static void SaveToFile(BufferedImage bi , String FileName) {
        try {
            File outputfile = new File(FileName);
            ImageIO.write(bi, "png", outputfile);
        } catch (IOException ex) {
        }
    }
}
